home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Yerk 3.6.6 / Asm source / Dictionary < prev    next >
Encoding:
Text File  |  1986-01-08  |  3.9 KB  |  121 lines  |  [TEXT/YERK]

  1.          dispose: [ getNext: self ]
  2.             dispose: ptr
  3.         THEN   ;M
  4.  
  5. ;CLASS
  6.  
  7. :CLASS Dictionary  <super Array
  8.  
  9. \ CHAIN - does the main work of methods ENTER & QUERY. Intended to be a private
  10. \   method for class DICTIONARY. Searchs the chain at a given bucket for
  11. \   string. If String not found then returns false, otherwise true. Objaddr
  12. \   points to last element in chain.
  13.     :M CHAIN:   { objAddr strObj \ oldAddr flag -- objAddr bool }
  14.         FALSE -> flag
  15.         BEGIN
  16.             get: strObj get: objAddr s=
  17.             IF
  18.                 TRUE -> flag
  19.             THEN
  20.             objAddr -> oldAddr
  21.             getnext: objAddr -> objAddr
  22.             objAddr 0= flag or
  23.         UNTIL
  24.         oldAddr flag
  25.     ;M
  26.  
  27. \ QUERY - returns value associated with String in dictionary. If string is
  28. \  not found in dictionary, then 0 is returned.
  29.     :M QUERY:   { strObj \ idx checkAddr val -- val }
  30.         get: strObj str255 -base hash limit: self mod -> idx
  31.         idx at: self -> checkAddr
  32.         checkAddr 0=
  33.         IF
  34.             0 -> Val
  35.         ELSE
  36.             checkAddr strObj chain: self swap -> checkAddr
  37.             IF
  38.                 getData: checkAddr -> val
  39.             ELSE
  40.                 0 -> val
  41.             THEN
  42.         THEN
  43.         val
  44.     ;M
  45.  
  46. \ ENTER - puts the string and value into the dictionary. If the string is
  47. \  already in the dictionary then it changes the value to the new value.
  48.     :M ENTER: { val strObj \ idx EltAddr OldAddr -- }
  49.         get: strObj str255 -base hash limit: super mod -> idx
  50.         idx at: super -> oldAddr 
  51.         oldAddr 0=
  52.         IF
  53.             Heap> DictElt -> EltAddr new: EltAddr
  54.             get: strObj put: EltAddr
  55.             val putData: EltAddr
  56.             EltAddr idx to: super
  57.         ELSE
  58.             oldAddr strObj chain: self swap -> oldAddr
  59.             IF
  60.                 val putData: oldAddr
  61.             ELSE
  62.                 heap> DictElt -> EltAddr new: EltAddr
  63.                 get: strObj put: EltAddr
  64.                 val putData: EltAddr
  65.                 EltAddr setNext: oldAddr
  66.             THEN
  67.         THEN
  68.     ;M
  69.  
  70. \ EXEC - for every element in the dictionary exec: executes routine with the 
  71. \  associated value and an addr/len pair representing the hashed string as 
  72. \  an argument
  73.     :M EXEC:    { routine \ objAddr -- }
  74.         limit: self 0 
  75.         DO
  76.             i at: self -> objAddr
  77.             objAddr 0= not
  78.             IF
  79.                 BEGIN
  80.                     getData: objAddr get: objAddr exec> routine
  81.                     getNext: objAddr -> objAddr
  82.                     objAddr 0=
  83.                 UNTIL
  84.             THEN
  85.         LOOP
  86.     ;M
  87.  
  88.     :M DISPOSE:
  89.         limit: super 0
  90.         DO
  91.             i at: super 0= not
  92.             IF
  93.                 dispose: [ i at: super ]
  94.                 i dispose: super
  95.             THEN
  96.         LOOP
  97.     ;M
  98.  
  99. ;CLASS
  100.  
  101. :CLASS Symbols <SUPER Dictionary
  102. \ QUERY - returns value associated with String in dictionary and FoundFlag. If
  103. \ string is not found in dictionary, then 0 0 is returned. Needed for SymTab
  104. \ where 0 is valid value.
  105.     :M QUERY:   { strObj \ idx checkAddr val found -- val found }
  106.         FALSE -> Found
  107.         get: strObj str255 -base hash limit: self mod -> idx
  108.         idx at: self -> checkAddr
  109.         checkAddr
  110.         IF
  111.             checkAddr strObj chain: self -> Found -> checkAddr
  112.             Found
  113.             IF
  114.                 getData: checkAddr -> val
  115.             THEN
  116.         THEN
  117.         val Found
  118.     ;M
  119.  
  120. ;CLASS
  121.